How to CPS Transform a Monad

نویسندگان

  • Annette Bieniusa
  • Peter Thiemann
چکیده

CPS transformation is an important tool in the compilation of functional programming languages. For strict languages, such as our web programming language “Rinso” or Microsoft’s F#, monadic expressions can help with structuring and composing computations. To apply a CPS transformation in the compilation process of such a language, we integrate explicit monadic abstraction in a call-by-value source language, present a Danvy-Filinski-style CPS transformation for this extension, and verify that the translation preserves simple typing. We establish the simulation properties of this transformation in an untyped setting and relate it to a two stage transformation that implements the monadic abstraction with thunks and introduces continuations in a second step. Furthermore, we give a direct style translation which corresponds to the monadic translation.

برای دانلود متن کامل این مقاله و بیش از 32 میلیون مقاله دیگر ابتدا ثبت نام کنید

ثبت نام

اگر عضو سایت هستید لطفا وارد حساب کاربری خود شوید

منابع مشابه

An Initial Model for the Monadic Calculus

When it comes to compiler design, there has been a dispute as to whether it is useful to transform the source code using the continuation passing style (CPS) transform first. Some have observed that it is easier to optimize CPS transformed code, while others maintain that direct style compilation is better. Sabry and Felleisen resolve the dispute by showing how get the benefits of CPS without t...

متن کامل

The selection monad as a CPS transformation

A computation in the continuation monad returns a final result given a continuation, ie. it is a function with type (X → R) → R. If we instead return the intermediate result at X then our computation is called a selection function. Selection functions appear in diverse areas of mathematics and computer science (especially game theory, proof theory and topology) but the existing literature does ...

متن کامل

Monad Translating Inductive and Coinductive Types

We show that the call-by-name monad translation of simply typed lambda calculus extended with sum and product types extends to special and general inductive and coinductive types so that its crucial property of preserving typings and βand commuting reductions is maintained. Specific similar-purpose translations such as CPS translations follow from the general monad translations by specializatio...

متن کامل

On the Overhead of CPS

Continuation-passing style (CPS) is often criticized to be more expensive than the usual direct style of functional programming. By structure, CPS functions indeed are passed one extra argument (the continuation), and each intermediate result indeed occurs in a function call (to the continuation). As higher-order functions, continuations are also more expensive. However, by structure also, CPS ...

متن کامل

A functional correspondence between monadic evaluators and abstract machines for languages with computational effects

We extend our correspondence between evaluators and abstract machines from the pure setting of the λ-calculus to the impure setting of the computational λ-calculus. We show how to derive new abstract machines from monadic evaluators for the computational λ-calculus. Starting from (1) a generic evaluator parameterized by a monad and (2) a monad specifying a computational effect, we inline the co...

متن کامل

ذخیره در منابع من


  با ذخیره ی این منبع در منابع من، دسترسی به آن را برای استفاده های بعدی آسان تر کنید

برای دانلود متن کامل این مقاله و بیش از 32 میلیون مقاله دیگر ابتدا ثبت نام کنید

ثبت نام

اگر عضو سایت هستید لطفا وارد حساب کاربری خود شوید

عنوان ژورنال:

دوره   شماره 

صفحات  -

تاریخ انتشار 2009